package com.eco.common.mapper.core.impl;

import com.eco.common.mapper.constant.MapperConstant;
import com.eco.common.mapper.core.FieldMapperInterface;
import com.eco.common.mapper.annotation.FieldMapperType;
import lombok.AllArgsConstructor;
import org.eco.common.core.service.DictService;
import org.eco.common.core.utils.StringUtils;

/**
 * @Description: DictTypeMapperImpl 字典映射
 * @Author: GaoKun Wang
 * @Date: 2024/7/1
 */
@AllArgsConstructor
@FieldMapperType(type = MapperConstant.DICT_TYPE_TO_LABEL)
public class DictTypeMapperImpl implements FieldMapperInterface<String> {
    private final DictService dictService;

    @Override
    public String fieldMapper(Object key, String other) {
        if (key instanceof String dictValue && StringUtils.isNotBlank(other)) {
            return dictService.getDictLabel(other, dictValue);
        }
        return null;
    }
}
